package com.gisocn.onemap.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.SeekBar;
import android.widget.Switch;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import butterknife.internal.Utils;
import com.gisocn.onemap.interfaces.OnChildItemCheckListener;
import com.gisocn.onemap.interfaces.OnChildSeekbarCheckListener;
import com.gisocn.onemap.model.TreePoint;
import com.gisocn.onemap.sgzx.R;
import com.gisocn.onemap.utils.tree.DensityUtil;
import java.util.HashMap;
import java.util.List;

/* loaded from: classes2.dex */
public class TreeLayerAdapter extends BaseAdapter {
    private Context mcontext;
    private OnChildItemCheckListener onChildItemCheckListener;
    private OnChildSeekbarCheckListener onChildSeekbarCheckListener;
    private List<TreePoint> pointList;
    private HashMap<String, TreePoint> pointMap;

    @Override // android.widget.Adapter
    public long getItemId(int i) {
        return i;
    }

    /* loaded from: classes2.dex */
    public class ViewHolder_ViewBinding implements Unbinder {
        private ViewHolder target;

        public ViewHolder_ViewBinding(ViewHolder viewHolder, View view) {
            this.target = viewHolder;
            viewHolder.layoutGroupAll = (LinearLayout) Utils.findRequiredViewAsType(view, R.id.layout_layer_manage_tree_group, "field 'layoutGroupAll'", LinearLayout.class);
            viewHolder.ivGroupLeft = (ImageView) Utils.findRequiredViewAsType(view, R.id.iv_layer_manage_tree_group_left, "field 'ivGroupLeft'", ImageView.class);
            viewHolder.tvGroupName = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_layer_manage_tree_group_name, "field 'tvGroupName'", TextView.class);
            viewHolder.viewGroupLarge = Utils.findRequiredView(view, R.id.view_layer_manage_tree_group_line_large, "field 'viewGroupLarge'");
            viewHolder.viewGroupSmall = Utils.findRequiredView(view, R.id.view_layer_manage_tree_group_line_small, "field 'viewGroupSmall'");
            viewHolder.layoutChildAll = (LinearLayout) Utils.findRequiredViewAsType(view, R.id.layout_layer_manage_tree_child, "field 'layoutChildAll'", LinearLayout.class);
            viewHolder.switchChild = (Switch) Utils.findRequiredViewAsType(view, R.id.switch_layer_manage_tree_child, "field 'switchChild'", Switch.class);
            viewHolder.tvChildName = (TextView) Utils.findRequiredViewAsType(view, R.id.tv_layer_manage_tree_child_name, "field 'tvChildName'", TextView.class);
            viewHolder.layoutSeekBar = (LinearLayout) Utils.findRequiredViewAsType(view, R.id.layout_layer_manage_tree_seekbar, "field 'layoutSeekBar'", LinearLayout.class);
            viewHolder.seekBarChild = (SeekBar) Utils.findRequiredViewAsType(view, R.id.seekbar_layer_manage_tree_child, "field 'seekBarChild'", SeekBar.class);
            viewHolder.viewChildLarge = Utils.findRequiredView(view, R.id.view_layer_manage_tree_child_line_large, "field 'viewChildLarge'");
        }

        @Override // butterknife.Unbinder
        public void unbind() {
            ViewHolder viewHolder = this.target;
            if (viewHolder == null) {
                throw new IllegalStateException("Bindings already cleared.");
            }
            this.target = null;
            viewHolder.layoutGroupAll = null;
            viewHolder.ivGroupLeft = null;
            viewHolder.tvGroupName = null;
            viewHolder.viewGroupLarge = null;
            viewHolder.viewGroupSmall = null;
            viewHolder.layoutChildAll = null;
            viewHolder.switchChild = null;
            viewHolder.tvChildName = null;
            viewHolder.layoutSeekBar = null;
            viewHolder.seekBarChild = null;
            viewHolder.viewChildLarge = null;
        }
    }

    public TreeLayerAdapter(Context context, List<TreePoint> list, HashMap<String, TreePoint> hashMap) {
        this.pointMap = new HashMap<>();
        this.mcontext = context;
        this.pointList = list;
        this.pointMap = hashMap;
    }

    public void setOnChildItemCheckListener(OnChildItemCheckListener onChildItemCheckListener) {
        this.onChildItemCheckListener = onChildItemCheckListener;
    }

    public void setOnChildSeekbarCheckListener(OnChildSeekbarCheckListener onChildSeekbarCheckListener) {
        this.onChildSeekbarCheckListener = onChildSeekbarCheckListener;
    }

    @Override // android.widget.Adapter
    public int getCount() {
        int i = 0;
        for (TreePoint treePoint : this.pointList) {
            if ("0".equals(treePoint.getPARENTID()) || getItemIsExpand(treePoint.getPARENTID())) {
                i++;
            }
        }
        return i;
    }

    private boolean getItemIsExpand(String str) {
        for (TreePoint treePoint : this.pointList) {
            if (str.equals(treePoint.getID())) {
                return treePoint.isExpand();
            }
        }
        return false;
    }

    @Override // android.widget.Adapter
    public Object getItem(int i) {
        return this.pointList.get(convertPostion(i));
    }

    private int convertPostion(int i) {
        int i2 = 0;
        for (int i3 = 0; i3 < this.pointList.size(); i3++) {
            TreePoint treePoint = this.pointList.get(i3);
            if ("0".equals(treePoint.getPARENTID()) || getItemIsExpand(treePoint.getPARENTID())) {
                i2++;
            }
            if (i == i2 - 1) {
                return i3;
            }
        }
        return 0;
    }

    @Override // android.widget.Adapter
    public View getView(final int i, View view, ViewGroup viewGroup) {
        final ViewHolder viewHolder;
        if (view == null) {
            view = LayoutInflater.from(this.mcontext).inflate(R.layout.layer_manage_tree_item, (ViewGroup) null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) view.getTag();
        }
        TreePoint treePoint = (TreePoint) getItem(i);
        if ("0".equals(treePoint.getPARENTID())) {
            viewHolder.layoutGroupAll.setVisibility(0);
            viewHolder.layoutChildAll.setVisibility(8);
            if (!treePoint.isExpand()) {
                viewHolder.ivGroupLeft.setImageResource(R.mipmap.icon_expand_group_right);
                viewHolder.viewGroupLarge.setVisibility(0);
                viewHolder.viewGroupSmall.setVisibility(8);
            } else {
                viewHolder.ivGroupLeft.setImageResource(R.mipmap.icon_expand_group_down);
                viewHolder.viewGroupLarge.setVisibility(8);
                viewHolder.viewGroupSmall.setVisibility(0);
            }
            if (i == this.pointList.size()) {
                viewHolder.viewGroupLarge.setVisibility(0);
                viewHolder.viewGroupSmall.setVisibility(8);
            }
            viewHolder.tvGroupName.setCompoundDrawablePadding(DensityUtil.dip2px(this.mcontext, 10.0f));
            viewHolder.tvGroupName.setText(treePoint.getNNAME());
        } else if (!"1".equals(treePoint.getISLEAF())) {
            viewHolder.layoutGroupAll.setVisibility(0);
            viewHolder.layoutChildAll.setVisibility(8);
            if (!treePoint.isExpand()) {
                viewHolder.ivGroupLeft.setImageResource(R.mipmap.icon_expand_child_close);
                viewHolder.viewGroupLarge.setVisibility(0);
                viewHolder.viewGroupSmall.setVisibility(8);
            } else {
                viewHolder.ivGroupLeft.setImageResource(R.mipmap.icon_expand_child_open);
                viewHolder.viewGroupLarge.setVisibility(8);
                viewHolder.viewGroupSmall.setVisibility(0);
            }
            if (i == this.pointList.size()) {
                viewHolder.viewGroupLarge.setVisibility(0);
                viewHolder.viewGroupSmall.setVisibility(8);
            }
            viewHolder.tvGroupName.setCompoundDrawablePadding(DensityUtil.dip2px(this.mcontext, 10.0f));
            viewHolder.tvGroupName.setText(treePoint.getNNAME());
        } else {
            viewHolder.layoutGroupAll.setVisibility(8);
            viewHolder.layoutChildAll.setVisibility(0);
            viewHolder.viewChildLarge.setVisibility(0);
            viewHolder.switchChild.setEnabled(treePoint.isEnable());
            viewHolder.switchChild.setOnCheckedChangeListener(null);
            viewHolder.switchChild.setChecked(treePoint.isOff());
            viewHolder.switchChild.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { // from class: com.gisocn.onemap.ui.adapter.TreeLayerAdapter.1
                @Override // android.widget.CompoundButton.OnCheckedChangeListener
                public void onCheckedChanged(CompoundButton compoundButton, boolean z) {
                    if (TreeLayerAdapter.this.onChildItemCheckListener != null) {
                        TreeLayerAdapter.this.onChildItemCheckListener.onItemClick(compoundButton, i, viewHolder.switchChild.isChecked());
                        TreeLayerAdapter.this.notifyDataSetChanged();
                    }
                }
            });
            viewHolder.layoutSeekBar.setVisibility(treePoint.isSeekBar() ? 0 : 8);
            viewHolder.seekBarChild.setEnabled(treePoint.isEnable());
            viewHolder.seekBarChild.setProgress(60);
            viewHolder.seekBarChild.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { // from class: com.gisocn.onemap.ui.adapter.TreeLayerAdapter.2
                @Override // android.widget.SeekBar.OnSeekBarChangeListener
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override // android.widget.SeekBar.OnSeekBarChangeListener
                public void onStopTrackingTouch(SeekBar seekBar) {
                }

                @Override // android.widget.SeekBar.OnSeekBarChangeListener
                public void onProgressChanged(SeekBar seekBar, int i2, boolean z) {
                    if (TreeLayerAdapter.this.onChildSeekbarCheckListener == null) {
                        viewHolder.seekBarChild.setVisibility(8);
                    }
                    if (z) {
                        TreeLayerAdapter.this.onChildSeekbarCheckListener.onSeekbarClick(seekBar, i, i2);
                    }
                }
            });
            viewHolder.tvChildName.setCompoundDrawablePadding(DensityUtil.dip2px(this.mcontext, 10.0f));
            viewHolder.tvChildName.setText(treePoint.getNNAME());
        }
        return view;
    }

    public void onItemClick(int i) {
        TreePoint treePoint = (TreePoint) getItem(i);
        if (!"1".equals(treePoint.getISLEAF())) {
            if (treePoint.isExpand()) {
                for (TreePoint treePoint2 : this.pointList) {
                    if (treePoint2.getPARENTID().equals(treePoint.getID()) && "0".equals(treePoint.getISLEAF())) {
                        treePoint2.setExpand(false);
                    }
                }
                treePoint.setExpand(false);
            } else {
                treePoint.setExpand(true);
            }
        }
        notifyDataSetChanged();
    }

    private String getSubmitResult(TreePoint treePoint) {
        StringBuilder sb = new StringBuilder();
        addResult(treePoint, sb);
        String sb2 = sb.toString();
        return sb2.endsWith("-") ? sb2.substring(0, sb2.length() - 1) : sb2;
    }

    private void addResult(TreePoint treePoint, StringBuilder sb) {
        if (treePoint == null || sb == null) {
            return;
        }
        sb.insert(0, treePoint.getNNAME() + "-");
        if ("0".equals(treePoint.getPARENTID())) {
            return;
        }
        addResult(this.pointMap.get(treePoint.getPARENTID()), sb);
    }

    /* loaded from: classes2.dex */
    class ViewHolder {
        @BindView(R.id.iv_layer_manage_tree_group_left)
        ImageView ivGroupLeft;
        @BindView(R.id.layout_layer_manage_tree_child)
        LinearLayout layoutChildAll;
        @BindView(R.id.layout_layer_manage_tree_group)
        LinearLayout layoutGroupAll;
        @BindView(R.id.layout_layer_manage_tree_seekbar)
        LinearLayout layoutSeekBar;
        @BindView(R.id.seekbar_layer_manage_tree_child)
        SeekBar seekBarChild;
        @BindView(R.id.switch_layer_manage_tree_child)
        Switch switchChild;
        @BindView(R.id.tv_layer_manage_tree_child_name)
        TextView tvChildName;
        @BindView(R.id.tv_layer_manage_tree_group_name)
        TextView tvGroupName;
        @BindView(R.id.view_layer_manage_tree_child_line_large)
        View viewChildLarge;
        @BindView(R.id.view_layer_manage_tree_group_line_large)
        View viewGroupLarge;
        @BindView(R.id.view_layer_manage_tree_group_line_small)
        View viewGroupSmall;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
